<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="单号" prop="code">
        <el-input v-model="queryParams.code" placeholder="请输入单号" clearable size="small"/>
      </el-form-item>
      <el-form-item label="提现账号" prop="accountName">
        <el-input v-model="queryParams.accountName" placeholder="请输入提现账号" clearable size="small"/>
      </el-form-item>
      <el-form-item label="提现渠道" prop="channel">
         <el-select v-model="queryParams.channel" placeholder="请选择" clearable size="small">
          <el-option label="全部" value="" />
          <el-option label="app" :value="0" />
          <el-option label="微信" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable size="small">
          <el-option label="全部" value="" />
          <el-option label="待审核" :value="0" />
          <el-option label="已通过" :value="1" />
          <el-option label="未通过" :value="2" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="userApplyWithdrawList">
      <el-table-column label="提现单号" align="center" prop="code" />
      <el-table-column label="申请时间" align="center" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现账号" align="center" prop="accountName" />

      <el-table-column label="支付宝账号" align="center" prop="accountName" />
      <el-table-column label="真实姓名" align="center" prop="accountName" />
      <el-table-column label="身份证" align="center" prop="accountName" />

      <el-table-column label="提现金额" align="center" prop="takeMoney">
        <template slot-scope="scope">
          <span v-if="scope.row.takeMoney">
            ￥{{scope.row.takeMoney}} 
            <span v-if="scope.row.uasFavor">
              {{'('+scope.row.uasFavor+' 宠爱值)'}} 
            </span>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="剩余宠爱值" align="center" prop="leftoverFavor" />
      <el-table-column label="提现费率" align="center" prop="rate">
        <template slot-scope="scope">
            {{scope.row.rate?scope.row.rate+'%':'--'}}
        </template>
      </el-table-column>
      <el-table-column label="到账金额" align="center" prop="arriveMoney">
        <template slot-scope="scope">
            {{scope.row.arriveMoney?'￥'+scope.row.arriveMoney:'--'}}
        </template>
      </el-table-column>
      <el-table-column label="提现渠道" align="center" prop="channel">
       <template slot-scope="scope">
          <span v-if="scope.row.channel === 0">app</span>
          <span v-else-if="scope.row.channel === 1">微信</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status === 0">待审核</span>
          <span v-else-if="scope.row.status === 1">已通过</span>
          <span v-else-if="scope.row.status === 2">未通过</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status === 0" size="mini" type="text" @click="handleUpdate(scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="提现申请审核" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="申请账号" >
          {{form.accountName}}
        </el-form-item>
        <el-form-item label="提现申请审核" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio :label="1">审核通过</el-radio>
            <el-radio :label="2">审核不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="原因" prop="appylyText">
          <el-input type="textarea" v-model="form.appylyText" :rows="3"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listUserApplyWithdraw, getUserApplyWithdraw, updateUserApplyWithdraw } from "@/api/system/userApplyWithdraw";

export default {
  name: "UserApplyWithdraw",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 用户提现申请表格数据
      userApplyWithdrawList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: undefined,
        accountName: undefined,
        rate: undefined,
        channel: undefined,
        status: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { required: true, message: "请选择审核状态", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户提现申请列表 */
    getList() {
      this.loading = true;
      listUserApplyWithdraw(this.queryParams).then(response => {
        this.userApplyWithdrawList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getUserApplyWithdraw(id).then(response => {
        this.form = response.data;
        this.open = true;
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateUserApplyWithdraw(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }
          });
        }
      });
    },
  }
};
</script>